#pragma once
#include"RedBlackTree.h"

namespace my_set
{
	template<class K>
	class set
	{
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename RedBlackTree<K, const K, SetKeyOfT>::iterator iterator;
		typedef typename RedBlackTree<K, const K, SetKeyOfT>::const_iterator const_iterator;

		iterator begin()
		{
			return _rbtree.begin();
		}

		iterator end()
		{
			return _rbtree.end();
		}

		const_iterator begin() const
		{
			return _rbtree.begin();
		}

		const_iterator end() const
		{
			return _rbtree.end();
		}

		std::pair<iterator, bool> insert (const K& key)
		{
			return _rbtree.insert(key);
		}

		void inorder()
		{
			_rbtree.inorder();
		}

		iterator find()
		{
			return _rbtree.find();
		}

	private:
		RedBlackTree<K, const K, SetKeyOfT> _rbtree;
	};

	void test_set()
	{
		std::cout << " ------test_set()  ------ " << std::endl;
		set<int> s;
		s.insert(4);
		s.insert(2);
		s.insert(1);
		s.insert(3);

		s.inorder();

		set<int>::iterator it1 = s.begin();
		while (it1 != s.end())
		{
			std::cout << *it1 << " ";
			++it1;
		}
		std::cout << std::endl;

		set<int>::iterator it2 = s.end();
		while (it2 != s.begin())
		{
			--it2;
			std::cout << *it2 << " ";
		}
		std::cout << std::endl;


		std::cout << "----------------------------------" << std::endl;

	}
}
